import os

os.chdir("/Users/ddy/Py/test")
'''
    文件替换字符串
'''
with open("test_range_w.txt", '+r') as f:
    content = f.read()
    content = content.replace("timess","times")
    f.seek(0, 0)  # 读写偏移位置移到最开始处
    f.write(content)
